<?php
namespace app\lib\baidu;
use think\Db;

class Moonshot 
{

    public function chat($api_url,$api_param,$messages){
        $params = [
            'model'=>$api_param['model'],
            'messages'=>$messages
        ];
        $result = httpRequest($api_url,json_encode($params,JSON_UNESCAPED_UNICODE),'POST',[
            'Content-Type:application/json',
            'Authorization:Bearer '.$api_param['key']
        ]);
        $result = json_decode($result,true);
        if (!empty($result['choices'][0])) {
            return ['status'=>1,'answer'=>$result['choices'][0]['message']['content']];
        }else{
            return ['status'=>0,'msg'=>$result['error']['message']];
        }
    }

}
